<?php
class c_laporan extends CI_Controller {
	function __construct(){
		parent::__construct();
        $this->load->model("m_laporan");
        $this->load->helper("date");
        $this->load->helper("romawi_helper");
	}
	function index(){
		$task = secure_post('task');
		$type = secure_post('type');
		$search = secure_post('search');
        
		switch($task){
			case "list_proyek":
				$this->_list_proyek($type,$search);
				break;
			case "list_mandor":
				$this->_list_mandor($type,$search);
				break;
			case "mon_mandor":
				$this->_mon_mandor($type,$search);
				break;
			case "mon_harsat":
				$this->_mon_harsat($type,$search);
				break;
			case "re_proyek":
				$this->_re_proyek($type,$search);
				break;
			case "re_cabang":
				$this->_re_cabang($type,$search);
				break;
			case "re_dvo":
				$this->_re_dvo($type,$search);
				break;
			case "re_harsat":
				$this->_re_harsat($type,$search);
				break;
			case "re_harsat":
				$this->_re_harsat($type,$search);
				break;
            case "map_mandor" :
				$this->_map_mandor($type,$search);
				break;
            case "map_mandor_selesai" :
				$this->_map_mandor_selesai($type,$search);
				break;
			default : 
				$this->_map_mandor();
		}
	}
	
	function _list_proyek($ajax = "", $search = ""){
        $data["data"] = $this->m_laporan->_list_proyek($search);
		$html = $this->load->view("print/list_proyek",$data, true);
        if ($ajax != ""){echo $html;}else{$this->_view($html,"list_proyek.html");} 
        $this->_print($html,"list_proyek.html"); 
	}
    
	function _list_mandor($ajax = "", $search = ""){
        $data["data"] = $this->m_laporan->_list_mandor($search);
        $data["pekerjaan"] = $this->m_public_function->_pekerjaan(0);
		$html = $this->load->view("print/list_mandor",$data, true);
        if ($ajax != ""){echo $html;}else{$this->_view($html,"list_mandor.html");} 
        $this->_print($html,"list_mandor.html"); 
	}
    
	function _mon_mandor($ajax = "", $search = ""){
        $data["data"] = $this->m_laporan->_mon_mandor($search);
		$html = $this->load->view("print/mon_mandor",$data, true);
        if ($ajax != ""){echo $html;}else{;$this->_view($html,"mon_mandor.html");} 
        $this->_print($html,"mon_mandor.html"); 
	}
    
	function _mon_harsat($ajax = "", $search = ""){
        $data["data"] = $this->m_laporan->_mon_harsat($search);
		$html = $this->load->view("print/mon_harsat",$data, true);
        if ($ajax != ""){echo $html;}else{;$this->_view($html,"mon_harsat.html");} 
        $this->_print($html,"mon_harsat.html"); 
	}
    
	function _re_cabang($ajax = "", $search = ""){
        $post["cabang_id"] = secure_post("cabang_id");
        $post["bulan"] = secure_post("bulan");
        $post["search"] = $search;
        
        $data["data"] = $this->m_laporan->_re_cabang($post);
		$html = $this->load->view("print/re_cabang",$data, true);
        $type = secure_post("type");
        if ($type == "filter"){
             echo $html;
        }else{
            $optional = $this->load->view("print/re_cabang",array("type"=>"optional"), true);
        if ($ajax != ""){echo $html;}else{$this->_view($html,"re_cabang.html",$optional);} 
        $this->_print($html,"re_cabang.html"); 
        }
	}
    
	function _re_proyek($ajax = "", $search = ""){
        $post["proyek_id"] = secure_post("proyek_id");
        $post["bulan"] = secure_post("bulan");
        $post["search"] = $search;
        
        $data["data"] = $this->m_laporan->_re_proyek($post);
		$html = $this->load->view("print/re_proyek",$data, true);
        $type = secure_post("type");
        if ($type == "filter"){
             echo $html;
        }else{
            $optional = $this->load->view("print/re_proyek",array("type"=>"optional"), true);
            
            if ($ajax != ""){echo $html;}else{$this->_view($html,"re_proyek.html",$optional);} 
            $this->_print($html,"re_proyek.html"); 
        }
	}
    
	function _re_dvo($ajax = "", $search = ""){
        $post["bulan"] = secure_post("bulan");
        $post["search"] = $search;
        $data["data"] = $this->m_laporan->_re_dvo($post);
        $data["pekerjaan"] = $this->m_public_function->_pekerjaan(0);
		$html = $this->load->view("print/re_dvo",$data, true);
        $type = secure_post("type");
        if ($type == "filter"){
             echo $html;
        }else{
            $optional = $this->load->view("print/re_dvo",array("type"=>"optional"), true);
            if ($ajax != ""){echo $html;}else{$this->_view($html,"re_dvo.html",$optional);} 
            $this->_print($html,"re_dvo.html"); 
        }
	}
    
	function _re_harsat($ajax = "", $search = ""){
        $pekerjaan_id = $this->input->post("pekerjaan_id");
        if (!is_array($pekerjaan_id) )
            $pekerjaan_id = array($pekerjaan_id );
        $post["pekerjaan_id"] = implode(",",$pekerjaan_id);
        $post["search"] = $search;
        $data["data"] = $this->m_laporan->_re_harsat($post);
		$html = $this->load->view("print/re_harsat",$data, true);
        $type = secure_post("type");
        if ($type == "filter"){
             echo $html;
        }else{
            $optional = $this->load->view("print/re_harsat",array("type"=>"optional"), true);
        if ($ajax != ""){echo $html;}else{$this->_view($html,"re_harsat.html",$optional);} 
        $this->_print($html,"re_harsat.html");
        }
	}
    
	function _map_mandor($ajax = "", $search = ""){
        $pekerjaan_id = $this->input->post("pekerjaan_id");
        if (!is_array($pekerjaan_id) )
            $pekerjaan_id = array($pekerjaan_id );
        $post["pekerjaan_id"] = implode(",",$pekerjaan_id);
        $post["search"] = $search;
        $data["data"] = $this->m_laporan->_map_mandor($post);
        $data["pekerjaan"] = $this->m_public_function->_pekerjaan(0);
		$html = $this->load->view("print/map_mandor",$data, true);
        $type = secure_post("type");
        if ($type == "filter"){
             echo $html;
        }else{
            $optional = $this->load->view("print/map_mandor",array("type"=>"optional"), true);
        if ($ajax != ""){echo $html;}else{$this->_view($html,"map_mandor.html",$optional);} 
        $this->_print($html,"map_mandor.html"); 
        }
	}
    
	function _map_mandor_selesai($ajax = "", $search = ""){
        $pekerjaan_id = $this->input->post("pekerjaan_id");
        if (!is_array($pekerjaan_id) )
            $pekerjaan_id = array($pekerjaan_id );
        $post["pekerjaan_id"] = implode(",",$pekerjaan_id);
        $post["search"] = $search;
        $data["data"] = $this->m_laporan->_map_mandor_selesai($post);
        $data["pekerjaan"] = $this->m_public_function->_pekerjaan(0);
		$html = $this->load->view("print/map_mandor_selesai",$data, true);
        $type = secure_post("type");
        if ($type == "filter"){
             echo $html;
        }else{
        if ($ajax != ""){echo $html;}else{$this->_view($html,"map_mandor_selesai.html");} 
        $this->_print($html,"map_mandor_selesai.html"); 
        }
	}
    
    function _view($html, $filename, $optional = ""){
        $this->load->view("print/template_view",array("html" => $html, "filename" => $filename, "optional" => $optional));
        
        
    }
	
    function _print($html, $filename){
        $html = $this->load->view("print/template_print",array("html" => $html),true);
        $file = fopen("print/".$filename, "w+");
        fwrite($file,$html);
        fclose($file);
    }
}